package com.sugar.subscribe.course.module.business.controller.app.coachvideo;

import com.sugar.subscribe.course.framework.common.pojo.CommonResult;
import com.sugar.subscribe.course.framework.common.pojo.PageParam;
import com.sugar.subscribe.course.framework.common.pojo.PageResult;
import com.sugar.subscribe.course.framework.common.util.object.BeanUtils;
import com.sugar.subscribe.course.framework.security.core.util.SecurityFrameworkUtils;
import com.sugar.subscribe.course.module.business.controller.admin.coachvideo.vo.CoachVideoRespVO;
import com.sugar.subscribe.course.module.business.controller.app.coachvideo.vo.AppCoachVideoRespVO;
import com.sugar.subscribe.course.module.business.controller.app.coachvideo.vo.AppCoachVideoSaveReqVO;
import com.sugar.subscribe.course.module.business.controller.app.coachvideo.vo.UserAppCoachVideoRespVO;
import com.sugar.subscribe.course.module.business.service.coachvideo.CoachVideoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.annotation.security.PermitAll;
import javax.validation.Valid;

import static com.sugar.subscribe.course.framework.common.pojo.CommonResult.success;

@Tag(name = "APP - 教练视频介绍")
@RestController
@RequestMapping("/biz/coach-video")
@Validated
public class AppCoachVideoController {

    @Resource
    private CoachVideoService coachVideoService;

    @PostMapping("/create")
    @Operation(summary = "教练端 - 创建教练视频介绍")
    public CommonResult<Boolean> createCoachVideo(@Valid @RequestBody AppCoachVideoSaveReqVO createReqVO) {
        coachVideoService.appCreateCoachVideo(createReqVO, SecurityFrameworkUtils.getLoginUserId(true));
        return success(true);
    }

    @GetMapping("/delete")
    @Operation(summary = "教练端 - 删除教练视频介绍")
    @Parameter(name = "id", description = "编号", required = true)
    public CommonResult<Boolean> deleteCoachVideo(@RequestParam("id") Long id) {
        coachVideoService.deleteCoachVideo(id);
        return success(true);
    }

    @GetMapping("/page")
    @Operation(summary = "教练端 - 获得教练视频介绍分页")
    public CommonResult<PageResult<AppCoachVideoRespVO>> getCoachVideoPage(@Valid PageParam pageParam) {
        return success(coachVideoService.appGetCoachVideoPage(pageParam, SecurityFrameworkUtils.getLoginUserId(true)));
    }

    @GetMapping("/page/{coachId}")
    @Operation(summary = "用户端 - 获得教练视频介绍分页")
    @PermitAll
    public CommonResult<PageResult<UserAppCoachVideoRespVO>> getCoachVideoPage(@Valid PageParam pageParam, @PathVariable("coachId") Long coachId) {
        return success(BeanUtils.toBean(coachVideoService.appGetCoachVideoPage(pageParam, coachId), UserAppCoachVideoRespVO.class));
    }
}